import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 导航传递参数到父页面
 */
class MyApp17 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "BottomNavigationWidget",
      theme: ThemeData(primarySwatch: Colors.lightBlue),
      home: BottomAppBarDemo(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class BottomAppBarDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return BottomAppBarDemoState();
  }
}

class BottomAppBarDemoState extends State<BottomAppBarDemo> {
  List<Widget> list = List();
  int currentIndex = 0;

  @override
  void initState() {
    super.initState();
    list.add(EachView("HOME"));
    list.add(EachView("AIRPLAY"));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //可交互的浮动按钮
      floatingActionButton: FloatingActionButton(
        //长按显示的提示文字
        tooltip: 'Increment',
        //放置子元素，一般放置Icon Widget
        child: Icon(
          Icons.add,
          color: Colors.white,
        ),
        onPressed: () {
          Navigator.of(context).push(
              MaterialPageRoute(builder: (context) => EachView("Increment View")));
        },
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,

      body: list[currentIndex],
      //BottomAppBar 是 底部工具栏的意思
      bottomNavigationBar: BottomAppBar(
        color: Colors.lightBlue,
        //设置底栏的形状，一般使用这个都是为了和floatingActionButton融合，所以使用的值都是CircularNotchedRectangle(),有缺口的圆形矩形。
        shape: CircularNotchedRectangle(),
        //里边可以放置大部分Widget，让我们随心所欲的设计底栏。
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            IconButton(
                icon: Icon(Icons.home), color: Colors.white, onPressed: () {
              setState(() {
                currentIndex = 0;
              });
            }),
            IconButton(
                icon: Icon(Icons.airplay),
                color: Colors.white,
                onPressed: () {
                  setState(() {
                    currentIndex = 1;
                  });
                }),
          ],
        ),
      ),
    );
  }
}

class EachView extends StatefulWidget {
  String title;

  EachView(this.title);

  @override
  State<StatefulWidget> createState() {
    return EachViewState();
  }
}

class EachViewState extends State<EachView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text(widget.title),),
        body: Center(
          child: Text(widget.title),
        )
    );
  }
}
